CheckUserPortlet = Class.extend({
	init: function()	{
		this.name = "CheckUserPortlet";
		this.sbj = SingletonFactory.getInstance(Subject);
	},
	
	onBegin: function()	{
		this.registerObserver();
	},
	
	run: function()	{
		this.getPortletPlaceholder().paintCanvas(this.render());
		var search = this.requestForEffectiveResource('Input');
		this.sbj.notifyEvent('AttachFocusDetection', {'target': search, 'defaultValue': 'Nhập email hoặc username để kiểm tra'});
		this.sbj.notifyEvent('ReloadUserCheck');
	},
	
	onRewardUser: function(eventData)	{
		var id = eventData.id;
		var obj = this;
		this.onAjax('manager', 'reward-user', {id: id}, 'POST', {
			'onSuccess': function(ret)	{
				obj.sbj.notifyEvent('ReloadUserCheck');
			}
		});
	},
	
	onUndoUser: function(eventData)	{
		var id = eventData.id;
		var obj = this;
		this.onAjax('manager', 'undo-reward-user', {id: id}, 'POST', {
			'onSuccess': function(ret)	{
				obj.sbj.notifyEvent('ReloadUserCheck');
			}
		});
	},
	
	onReloadUserCheck: function()	{
		var search = this.requestForEffectiveResource('Input');
		var kw = '';
		if (!search.hasClass('joo-non-focus'))	{
			kw = search.val();
		}
		var obj = this;
		this.onAjax('manager', 'find-user', {'keyword': kw}, 'GET', {
			'onSuccess': function(ret)	{
				obj.requestForEffectiveResource('List').html(obj.renderView('ListTmpl', {users: ret}));
			}
		});
		this.onAjax('manager', 'count-rewarded-users', {}, 'GET', {
			'onSuccess': function(ret)	{
				obj.requestForEffectiveResource('No').html(ret);
			}
		});
	},
	
	onEnd: function()	{
		this.unregisterObserver();
	}
}).implement(PortletInterface).implement(AjaxInterface).implement(RenderInterface).implement(ObserverInterface);